package esb.chapter9.restaurant.routing.camel;

import org.apache.camel.builder.RouteBuilder;
import org.apache.camel.builder.xml.XPathBuilder;

public class ExpirationCheckFilter extends RouteBuilder {
	
	private final static String SERVICE_IN = RestaurantRouter.JBI_PREFIX + 
		"/expirationDSLFilter";
	private final static String REPLY_OUT = RestaurantRouter.JBI_PREFIX +
		"/lcdConfirmation";
	private final static String LAKEVIEW_OUT = RestaurantRouter.JBI_PREFIX + 
		"/lakeviewConfirmation";
	private final static String YOKOHAMA_OUT = RestaurantRouter.JBI_PREFIX + 
		"/yokohamaConfirmation";
	private final static String DUCK_OUT = RestaurantRouter.JBI_PREFIX + 
		"/duckConfirmation";
	private final static String ERROR_OUT = RestaurantRouter.JBI_PREFIX + 
		"/errorConfirmation";
	private final static String SEDA_CHOICE = "seda:restaurantChoice"; 
	
	public void configure() {
		from(SERVICE_IN).errorHandler(deadLetterChannel(ERROR_OUT).maximumRedeliveries(1))
			.process(new ExpirationCheckProcessor())
			.multicast().to(REPLY_OUT, SEDA_CHOICE);
		
		from(SEDA_CHOICE)
			.choice()
				.when(XPathBuilder.xpath("//restaurant='Lakeview'"))
					.to(LAKEVIEW_OUT)
				.when(XPathBuilder.xpath("//restaurant='Yokohama'"))
					.to(YOKOHAMA_OUT)
				.otherwise()
					.to(DUCK_OUT);
	}

}
